package cubelabs.nexus.utils;

import java.util.ArrayList;
import java.util.List;

import cubelabs.nexus.domain.CategoryDTO;
import cubelabs.nexus.domain.InvitationDTO;
import cubelabs.nexus.domain.SessionDTO;
import cubelabs.nexus.domain.UserDTO;
import cubelabs.nexus.entity.Category;
import cubelabs.nexus.entity.Invitation;
import cubelabs.nexus.entity.Session;
import cubelabs.nexus.entity.User;
import java.util.Collection;

public class GenericUtils {

	public static UserDTO getUserDTO(User user){
		UserDTO userDTO = new UserDTO();
		userDTO.setActive(user.isActive());
		userDTO.setId(user.getId());
		userDTO.setEmail(user.getEmail());
		userDTO.setEmailValidated(user.isEmailValidated());
		userDTO.setLastLogin(user.getLastLogin());
		userDTO.setName(user.getName());
		userDTO.setImagePath(user.getImagePath());
		return userDTO;
	}
	
	public static List<UserDTO> getUserDTO(Collection<User> userList){
		List<UserDTO> userDTOs = null;
		if(userList != null && userList.size() > 0){
			userDTOs = new ArrayList<UserDTO>();
			for(User user: userList){
				userDTOs.add(getUserDTO(user));
			}
		}
		return userDTOs;
	}
	
	public static InvitationDTO convertInvitation(Invitation invitation) {
		InvitationDTO invitationDTO = new InvitationDTO();
		invitationDTO.setFrmuserDTO(getUserDTO(invitation.getInviter()));
		invitationDTO.setToUserDTO(getUserDTO(invitation.getInvitee()));
		invitationDTO.setSessionDTO(convertSession(invitation.getSession()));
		invitationDTO.setFromEmail(invitation.getInviterEmail());
		invitationDTO.setToEmail(invitation.getInviteeEmail());
		invitationDTO.setId(invitation.getId());
		return invitationDTO;
	}
	
	public static SessionDTO convertSession(Session session) {
		SessionDTO sessionDTO = new SessionDTO();
		sessionDTO.setCategory(convertCategory(session.getCategory()));
		sessionDTO.setStartTime(session.getStartTime());
		sessionDTO.setEndTime(session.getEndTime());
		sessionDTO.setHtmlDescription(session.getHtmlDescription());
		sessionDTO.setTitle(session.getTitle());
		sessionDTO.setPrice(session.getPrice());
		sessionDTO.setId(session.getId());
		return sessionDTO;
	}
	
	public static CategoryDTO convertCategory(Category category){
		CategoryDTO categoryDTO = new CategoryDTO();
		categoryDTO.setId(category.getId());
		categoryDTO.setName(category.getName());
		return categoryDTO;
	}
}
